package com.dkm.ec.home.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dkm.base.db.mybatis.impl.domain.MyBatisPage;
import com.dkm.ec.home.constants.HomeEntityConstants;
import com.dkm.ec.home.domain.HomeEntity;
import com.dkm.ec.home.persistence.dao.HomeEntityQueryDao;
import com.dkm.ec.home.persistence.entity.HomeEntityPo;
import com.dkm.ec.home.repository.HomeEntityRepository;
import com.dkm.ec.home.service.HomeEntityService;

@Service
public class HomeEntityServiceImpl implements HomeEntityService{

	@Resource
	private HomeEntityRepository homeEntityRepository;
	
	@Resource
	private HomeEntityQueryDao homeEntityQueryDao;
	
	@Override
	public List<HomeEntityPo> findScenes() {
		return findScenes(0,999999);
	}

	@Override
	public List<HomeEntityPo> findScenes(int start, int pageSize) {
		MyBatisPage myBatisPage = new MyBatisPage(start,pageSize);
		List<HomeEntityPo> homeEntityPos =homeEntityQueryDao.findByHomeType(HomeEntityConstants.HOME_TYPE.SCENE,myBatisPage);
		for (HomeEntityPo homeEntityPo:homeEntityPos) {
			HomeEntity homeEntity = homeEntityRepository.newInstance(homeEntityPo);
			homeEntity.loadForDetail();
			//homeEntity.loadEntitySeo();
			homeEntity.loadEntityMedia();
			homeEntity.loadSolrValues();
			homeEntity.loadStyleKeys();
		}
		return homeEntityPos;
	}

	@Override
	public List<HomeEntityPo> findWholes() {
		return findWholes(0, 999999);
	}

	@Override
	public List<HomeEntityPo> findWholes(int start, int pageSize) {
		MyBatisPage myBatisPage = new MyBatisPage(start,pageSize);
		List<HomeEntityPo> homeEntityPos =homeEntityQueryDao.findByHomeType(HomeEntityConstants.HOME_TYPE.WHOLE,myBatisPage);
		for (HomeEntityPo homeEntityPo:homeEntityPos) {
			HomeEntity homeEntity = homeEntityRepository.newInstance(homeEntityPo);
			homeEntity.loadForDetail();
			//homeEntity.loadEntitySeo();
			homeEntity.loadEntityMedia();
			homeEntity.loadSolrValues();
			homeEntity.loadStyleKeys();
		}
		return homeEntityPos;
	}
	
}
